<template>
  <div class="menu">
    <div class="menu-btn" v-show="!showMenu" @click="handleMenu">
      <i class="iconfont icon-icmenu2"></i>功能
    </div>
    <div class="menu-btn" v-show="showMenu" @click="handleMenu">
      <i class="iconfont icon-close"></i>
    </div>
    <div class="menu-list" v-show="showMenu">
      <div class="menu-btn" @click="goMy">个人中心</div>
      <div class="menu-btn" @click="seeApplies">申请同桌</div>
      <div :class="[order_id==''?'disable':'','menu-btn']" @click="pay">结账</div>
      <div :class="[order_id==''?'disable':'','menu-btn']" @click="goOrders">已下单</div>
      <div class="menu-btn" @click="goShopMess">购物车</div>
      <div class="menu-btn" @click="goDishList">菜单</div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'

export default {
  name: 'shopMenu',
  components: {
  },
  data() {
    return {
      showMenu: false,
      order_id: '',
      id: 0,
      allPrice: 0
    }
  },
  activated() {
    this.showMenu=false
  },
  methods: {
    //显示和隐藏功能按钮
    handleMenu() {
      this.showMenu = !this.showMenu
      let id = this.getUrlParmas('id')
      axios.post('api/listenStatus',{'id':id}).then( res => {
        if(res.data.data.order_authority) {
          if(res.data.data.order_authority.order_id){
            this.order_id = res.data.data.order_authority.order_id
          }else {
            this.order_id = ''
          }
        }else {
          this.order_id = ''
        }
      })
    },
    goShopMess() {
      this.$router.push({path: '/shopCartMess'})
    },
    goDishList() {
      this.$router.push({path: '/'})
    },
    goOrders() {
      if(this.order_id != '') {
        this.$router.push({path: '/orders'})
      }
    },
    pay() {
      if(this.order_id != '') {
        let allPrice = 0
        this.id = this.getUrlParmas('id')
        axios.post('api/scan_show_dish',{'id':this.id}).then( res => {
          console.log(res)
          if(res.data.code == 200) {
            res.data.data.forEach( val => {
              allPrice += Number(val.amount)
            });
            this.allPrice = allPrice.toFixed(2)
            this.$router.push({name: 'pay',params: {'order_id':this.order_id,'room_desk_id':this.id,'price':this.allPrice}})
          }else {
            this.$showModal(res.data.info,true,false,function() {},function() {})
          }
        }).catch( error => {
          console.log(error)
        })
        
      }
    },
    goMy() {
      window.location.href="https://www.zltgs.com/mobile/mine"
    },
    //申请使用人列表
    seeApplies() {
      this.$router.push({path: '/apply'})
    },
    //获取url参数
    getUrlParmas(name) {
      let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
      let r = window.location.search.substr(1).match(reg);
      if(r!=null)
      return unescape(r[2]);
      return null;
    }
  }
} 
</script>

<style lang="stylus" scoped>
@import "~styles/common.styl"
  .menu
    width 1.4rem
    height 0.8rem
    font-size 0.28rem
    line-height 0.8rem
    text-align center
    position relative
    .menu-btn
      width 100%;
      height 0.8rem;
      background rgba(32,29,26,.82);
      color #fff
      border-radius 0.4rem
      i 
        vertical-align center
        margin-right 0.04rem
      &.disable
        color #999
    .menu-list
      position absolute
      left 0
      bottom 0.8rem
      width 100%
      .menu-btn
        margin-bottom 0.3rem
</style>